﻿<%@ Page Language="C#" MasterPageFile="~/SiteWorx/ControlPanel.master" AutoEventWireup="true" CodeFile="ProductCatalogManager.aspx.cs" Inherits="SiteWorx_ProductCatalogManager" Title="Product Catalog Manager" Theme="Admin" StylesheetTheme="Admin"%>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Csla" Namespace="Csla.Web" TagPrefix="cc1" %>
<asp:Content ID="cntHead" runat="server" ContentPlaceHolderID="head">

    <script type="text/javascript">
        function OpenFileExplorerDialog() {
            var wnd = $find("<%= ProductImageSelectWindow.ClientID %>");
            wnd.show();
        }

        function OnFileSelected(wnd, fileSelected) {
            var textbox = document.getElementById('ctl00_cphMain_fvProduct_txtProductImagePath');
            textbox.value = fileSelected;
        }
    </script>

</asp:Content>
<asp:Content ID="cntMain" ContentPlaceHolderID="cphMain" runat="Server">
    <telerik:RadAjaxPanel runat="server" ID="rapnlProductCatMaint" HorizontalAlign="NotSet"
        LoadingPanelID="ralProductCatMaint">
        <span class="siteWorxTitle">Product Catalog Manager</span>
        <asp:MultiView runat="server" ID="mvwProductCatalog" ActiveViewIndex="0">
            <asp:View runat="server" ID="vwCatalogList">
                <fieldset style="width: 810px;">
                    <legend>Product Catalog List</legend>
                    <telerik:RadGrid ID="rgvCatalog" runat="server" Skin="Telerik" HorizontalAlign="NotSet"
                        AutoGenerateColumns="False" DataSourceID="cdsProductCatalogList" 
                        Width="800px" ondeletecommand="rgvCatalog_DeleteCommand" 
                        onitemcommand="rgvCatalog_ItemCommand">
                        <HeaderContextMenu EnableTheming="True">
                            <CollapseAnimation Duration="200" Type="OutQuint" />
                        </HeaderContextMenu>
                        <MasterTableView DataSourceID="cdsProductCatalogList">
                            <Columns>
                                <telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name">
                                    <ItemTemplate>
                                        <asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle Width="680px" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="EditButton">
                                    <ItemTemplate>
                                        <asp:Button ID="btnEdit" runat="server" CausesValidation="False" CommandName="Select"
                                            Text="Edit" CommandArgument='<%# Bind("ID") %>' />
                                    </ItemTemplate>
                                    <ItemStyle Width="60px" HorizontalAlign="Right" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridButtonColumn UniqueName="DeleteButton" ItemStyle-Width="60px" CommandName="Delete"
                                    ConfirmDialogType="RadWindow" ConfirmText="Delete product catalog. Are you sure?"
                                    Text="Delete" ConfirmTitle="Delete Product Catalog" ButtonType="PushButton">
                                </telerik:GridButtonColumn>
                            </Columns>
                            <EditFormSettings>
                                <EditColumn UniqueName="EditCommandColumn">
                                </EditColumn>
                            </EditFormSettings>
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn>
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                        </MasterTableView>
                        <FilterMenu EnableTheming="True">
                            <CollapseAnimation Duration="200" Type="OutQuint" />
                        </FilterMenu>
                    </telerik:RadGrid>
                    <br />
                    <asp:Button ID="btnAddCatalog" runat="server" Text="Add New Catalog" 
                        CausesValidation="False" onclick="btnAddCatalog_Click" /></fieldset>
                <br />
                <br />
            </asp:View>
            <asp:View runat="server" ID="vwCatalog">
                <asp:FormView runat="server" ID="fvProductCatalog" DefaultMode="Edit" 
                    DataSourceID="cdsProductCatalog" ondatabound="fvProductCatalog_DataBound">
                    <EditItemTemplate>
                        <fieldset style="width: 810px;">
                            <legend>Product Catalog Details</legend>
                            <table border="0" class="form" width="800">
                                <tr>
                                    <td colspan="2">
                                        Fill out catalog properties below.<br />
                                        <br />
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top" align="right" class="label" style="width: 188px">
                                        *Name:
                                    </td>
                                    <td>
                                        <asp:TextBox runat="server" ID="txtCatalogName" Text='<%# Bind("Name") %>' Width="320px"
                                            MaxLength="100"></asp:TextBox>
                                        <br />
                                        <asp:RequiredFieldValidator ID="rfvProductName" runat="server" ControlToValidate="txtCatalogName"
                                            ErrorMessage="Product catalog name is required."></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top" align="right" class="label" style="width: 188px">
                                        Description:
                                    </td>
                                    <td>
                                        <asp:TextBox runat="server" ID="txtCatalogDescription" Text='<%# Bind("Description") %>'
                                            TextMode="MultiLine" Height="86px" Width="520px"></asp:TextBox>
                                        <br />
                                        <br />
                                    </td>
                                </tr>
                                <tfoot>
                                    <tr>
                                        <td colspan="2">
                                            <asp:Literal runat="server" ID="litCatalogUpdateSection"></asp:Literal>
                                        </td>
                                    </tr>
                                </tfoot>
                            </table>
                        </fieldset>
                    </EditItemTemplate>
                </asp:FormView>
                <asp:MultiView ID="mvwProducts" runat="server">
                    <asp:View ID="vwProducts" runat="server">
                        <fieldset style="width: 810px;">
                            <legend>Product List</legend>
                            <telerik:RadGrid ID="rgvProducts" runat="server" AutoGenerateColumns="False" DataSourceID="cdsProducts"
                                HorizontalAlign="NotSet" Skin="Telerik" Width="800px" 
                                ondeletecommand="rgvProducts_DeleteCommand" 
                                onitemcommand="rgvProducts_ItemCommand" onrowdrop="rgvProducts_RowDrop">
                                <HeaderContextMenu EnableTheming="True">
                                    <CollapseAnimation Duration="200" Type="OutQuint" />
                                </HeaderContextMenu>
                                <MasterTableView DataSourceID="cdsProducts" DataKeyNames="UniqueId">
                                    <Columns>
                                        <telerik:GridTemplateColumn HeaderText="Title" UniqueName="Title">
                                            <ItemTemplate>
                                                <asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
                                            </ItemTemplate>
                                            <ItemStyle Width="175px" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Item Number" UniqueName="ItemNumber">
                                            <ItemTemplate>
                                                <asp:Label ID="lblItemNumber" runat="server" Text='<%# Bind("ItemNumber") %>'></asp:Label>
                                            </ItemTemplate>
                                            <ItemStyle Width="110px" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Price" UniqueName="Price">
                                            <ItemTemplate>
                                                <asp:Label ID="lblPrice" runat="server" Text='<%# Bind("UnitPrice", "{0:c}")  %>'></asp:Label>
                                            </ItemTemplate>
                                            <ItemStyle Width="395px" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn UniqueName="EditButton">
                                            <ItemTemplate>
                                                <asp:Button ID="btnEdit" runat="server" CausesValidation="False" CommandArgument='<%# Bind("ID") %>'
                                                    CommandName="Select" Text="Edit" />
                                            </ItemTemplate>
                                            <ItemStyle Width="60px" HorizontalAlign="Right" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridButtonColumn UniqueName="DeleteButton" ItemStyle-Width="60px" CommandName="Delete"
                                            ConfirmDialogType="RadWindow" ConfirmText="Delete product. Are you sure?" Text="Delete"
                                            ConfirmTitle="Delete Product" ButtonType="PushButton">
                                        </telerik:GridButtonColumn>
                                    </Columns>
                                    <EditFormSettings>
                                        <EditColumn UniqueName="EditCommandColumn">
                                        </EditColumn>
                                    </EditFormSettings>
                                    <RowIndicatorColumn>
                                        <HeaderStyle Width="20px" />
                                    </RowIndicatorColumn>
                                    <ExpandCollapseColumn>
                                        <HeaderStyle Width="20px" />
                                    </ExpandCollapseColumn>
                                </MasterTableView>
                                <ClientSettings AllowRowsDragDrop="true">
                                    <Selecting AllowRowSelect="True" />
                                </ClientSettings>
                                <FilterMenu EnableTheming="True">
                                    <CollapseAnimation Duration="200" Type="OutQuint" />
                                </FilterMenu>
                            </telerik:RadGrid>
                            <br />
                            <asp:Button ID="btnAddProduct" runat="server" Text="Add a Product" 
                                CausesValidation="False" onclick="btnAddProduct_Click" />
                        </fieldset>
                        <br />
                        <asp:ValidationSummary runat="server" id="vsumProductCatalog" />
                        <br />
                        <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click"/>&nbsp;<asp:Button ID="btnCancel"
                            runat="server" CausesValidation="false" Text="Cancel" OnClick="btnCancel_Click" />
                    </asp:View>
                    <asp:View ID="vwProduct" runat="server">
                        <asp:FormView ID="fvProduct" runat="server" DataKeyNames="ID" DataSourceID="cdsProduct"
                            DefaultMode="Edit" ondatabound="fvProduct_DataBound" 
                            onitemcommand="fvProduct_ItemCommand" onitemupdated="fvProduct_ItemUpdated">
                            <EditItemTemplate>
                                <fieldset style="width: 810px;">
                                    <legend>Product Details</legend>
                                    <table border="0" class="form" width="800">
                                        <tr>
                                            <td align="right" style="width: 150px;" valign="top" class="label">
                                                *Title:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtProductTitle" runat="server" MaxLength="100" Text='<%# Bind("Title") %>'
                                                    Width="320px"> </asp:TextBox>
                                                <br />
                                                <asp:RequiredFieldValidator ID="rfvProductTitle" runat="server" ControlToValidate="txtProductTitle"
                                                    ErrorMessage="Product title is required." ValidationGroup="ProductDetails"></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" valign="top" class="label">
                                                Item number:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtItemNumber" runat="server" MaxLength="50" Text='<%# Bind("ItemNumber") %>'
                                                    Width="320px"> </asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" valign="top" class="label">
                                                Dimensions:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtDimensions" runat="server" MaxLength="50" Text='<%# Bind("Dimensions") %>'
                                                    Width="320px"> </asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" valign="top" class="label">
                                                Price:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtPrice" runat="server" MaxLength="50" Text='<%# Bind("UnitPrice") %>'
                                                    Width="320px"> </asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" valign="top" class="label">
                                                Description:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtProductDescription" runat="server" Height="56px" Text='<%# Bind("Description") %>'
                                                    TextMode="MultiLine" Width="320px"> </asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" valign="top" class="label">
                                                Image path:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtProductImagePath" runat="server" MaxLength="200" Text='<%# Bind("ImagePath") %>'
                                                    Width="320px"> </asp:TextBox>
                                                &nbsp;<input type="button" onclick="OpenFileExplorerDialog(); return false;" value="Select Image..." class="adminButton" />
                                                <br />
                                            </td>
                                        </tr>
                                        <tfoot>
                                            <tr>
                                                <td colspan="2">
                                                    <asp:Literal runat="server" ID="litProductUpdateSection"></asp:Literal>
                                                </td>
                                            </tr>
                                        </tfoot>
                                    </table>
                                    <br />
                                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Save" ValidationGroup="ProductDetails" />&nbsp;<asp:Button
                                        ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel" />
                                </fieldset>
                            </EditItemTemplate>
                        </asp:FormView>
                    </asp:View>
                </asp:MultiView>
            </asp:View>
        </asp:MultiView>
        <telerik:RadWindow runat="server" Width="730px" Height="445px" VisibleStatusbar="false"
            NavigateUrl="FileSelector.aspx" Skin="Telerik" ID="ProductImageSelectWindow" Modal="true"
            Behaviors="Resize, Close, Move" ShowContentDuringLoad="False">
        </telerik:RadWindow>
        <telerik:RadWindow runat="server" Width="730px" Height="445px" VisibleStatusbar="false"
            NavigateUrl="FileSelector.aspx" Skin="Telerik" ID="CatalogImageSelectWindow" Modal="true"
            Behaviors="Resize, Close, Move" ShowContentDuringLoad="False">
        </telerik:RadWindow>
    </telerik:RadAjaxPanel>
    <telerik:RadAjaxLoadingPanel ID="ralProductCatMaint" runat="server" Height="75px"
        Width="75px" Style="position: relative; top: -50%; left: 45%;" IsSticky="true">
        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'
            style="border: 0px;" />
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadWindowManager ID="rwmConfirm" runat="server" Skin="Telerik">
    </telerik:RadWindowManager>
    <cc1:CslaDataSource ID="cdsProductCatalogList" runat="server" TypeAssemblyName=""
        TypeName="Asah.SiteWorx.ProductCatalog.CatalogList, Asah" TypeSupportsPaging="False"
        TypeSupportsSorting="False" 
        onselectobject="cdsProductCatalogList_SelectObject">
    </cc1:CslaDataSource>
    <cc1:CslaDataSource ID="cdsProductCatalog" runat="server" TypeAssemblyName="" TypeName="Asah.SiteWorx.ProductCatalog.Catalog, Asah"
        TypeSupportsPaging="False" TypeSupportsSorting="False" 
        onselectobject="cdsProductCatalog_SelectObject" 
        onupdateobject="cdsProductCatalog_UpdateObject">
    </cc1:CslaDataSource>
    <cc1:CslaDataSource ID="cdsProducts" runat="server" TypeAssemblyName="" TypeName="Asah.SiteWorx.ProductCatalog.Products, Asah"
        TypeSupportsPaging="False" TypeSupportsSorting="False" 
        onselectobject="cdsProducts_SelectObject">
    </cc1:CslaDataSource>
    <cc1:CslaDataSource ID="cdsProduct" runat="server" TypeAssemblyName="" TypeName="Asah.SiteWorx.ProductCatalog.Product, Asah"
        TypeSupportsPaging="False" TypeSupportsSorting="False" 
        onselectobject="cdsProduct_SelectObject" 
        onupdateobject="cdsProduct_UpdateObject">
    </cc1:CslaDataSource>
</asp:Content>
